package com.ng.desktop.hr.view.customer;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.ng.desktop.hr.model.Customer;
import com.ng.desktop.hr.persistence.CustomerPersistence;
import com.ng.desktop.hr.services.NGFactoryBean;
import com.ng.framework.persistence.NGListingBean;
import com.ng.framework.persistence.NGSearchParameter.Type;
import com.ng.framework.persistence.NGSearchParameter.UnaryOperation;
import com.ng.framework.view.desktop.NGABMCFrame;
import com.ng.framework.view.desktop.NGEntitySelectorField;
import com.ng.framework.view.desktop.NGTablePanel;
import com.ng.framework.view.desktop.filters.NGComboFilter;
import com.ng.framework.view.desktop.filters.NGFilter;
import com.ng.framework.view.desktop.filters.NGTextFieldFilter;

public class CustomerFrame extends NGABMCFrame<Customer, CustomerPersistence> {

	private static final long serialVersionUID = -1306560836396996812L;

	private NGEntitySelectorField<Customer, CustomerPersistence> entitySelection;

	public CustomerFrame() {
		this.setTitle("Gestión de Clientes");
		this.setSize(new Dimension(1024, 600));
		this.centrar();
	}

	public CustomerFrame(NGEntitySelectorField<Customer, CustomerPersistence> entitySelection) {
		this();
		this.entitySelection = entitySelection;
	}

	@Override
	protected NGTablePanel<Customer, CustomerPersistence> createTable(CustomerPersistence persistence) {
		return new CustomerTablePanel(persistence, entitySelection);
	}

	@Override
	protected CustomerPersistence createPersistence() {
		return (CustomerPersistence) NGFactoryBean.getInstance().getBean("customerPersistence");
	}

	@Override
	protected List<NGFilter> createFilters() {

		List<NGListingBean> combo = new ArrayList<NGListingBean>();

		combo.add(new NGListingBean(1L, "Si"));
		combo.add(new NGListingBean(0L, "No"));

		NGFilter filtroPendiente = new NGComboFilter("Pendiente", Customer.class, "pending", Type.INTEGER, UnaryOperation.EQUALS,
				combo);
		return Arrays.asList(new NGFilter[]{
				new NGTextFieldFilter("Nombre", Customer.class, "name", Type.STRING, UnaryOperation.LIKE),
				new NGTextFieldFilter("Apellido", Customer.class, "lastName", Type.STRING, UnaryOperation.LIKE),
				new NGTextFieldFilter("Email", Customer.class, "emails", Type.STRING, UnaryOperation.LIKE, "literal"),
				filtroPendiente});
	}
}
